import React, { Component } from "react";
export default class Form extends Component {
  constructor() {
    super();
    this.state = {
      name: "",
      age: "",
    };
  }
  changeInp = (event) => {
   
    this.setState({
      [event.target.name]: event.target.value,
    });
    
  };
  add = () => {
    console.log(this.state);
    let obj = {  name: this.state.name, age: this.state.age ,id: +new Date()};
    this.props.addList(obj);
    console.log(this.props);
  };
  render() {
      let {name,age} = this.state
    return (
      <form action="">
        <div>
          <input
            type="text"
            value={name}
            name="name"
            onChange={this.changeInp}
          />
        </div>
        <div>
          <input type="text" value={age} name="age" onChange={this.changeInp} />
        </div>
        <div>
          <input type="button" value="添加" onClick={this.add} />
        </div>
      </form>
    );
  }
}
